/*
 * @Description  : 图表
 * @Author       : zhao
 * @Date         : 2022-07-26 09:23:39
 * @LastEditors  : zhao
 * @LastEditTime : 2023-02-01 14:42:04
 */
import { defineStore } from 'pinia';
import { ElMessage } from 'element-plus'
import {
    GetSearchRecoreSA,
    GetBrowsingRecoreSA,
    GetDivision,
    GetProBrowsingSA,
    GetGeoDataSA,
    GetBrowsingNumberSA,
    GetYearNewAddGetSA,
    GetYearNewAddBrowsingSA,
    GetHomeProBrowsingNumberSA,
    GetHomeProBrowsingCategorySA,
    GetHomeProBrowsingDistirctSA,
    Profession,
    GetMonthNewAddBrowsingSA,

    GetMonthNewAddGetSA,
    GetBrowsingNumberCategorySA,

    GetGeoDataYearSA,

    GetSearchRecoreYearSA,
    GetSearchRecoreMonthSA,
    GetSearchRecoreDaySA,
    GetBrowsingRecoreYearSA,
    GetBrowsingRecoreMonthSA,
    GetBrowsingRecoreDaySA,

    GetBrowseNumberYearSA,
    GetBrowseNumberMonthSA,
    GetBrowseNumberDaySA,

    GetGeoDataByYearSA

} from "/@/api/chart.js"
import { maxHeaderSize } from 'http';
export const useChart = defineStore('chart', {
    state: () => ({

    }),
    actions: {
        //CS当前馆藏资料统计--按类型分布
        getSearchRecoreSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetSearchRecoreSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //edit系统用户
        getBrowsingRecoreSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowsingRecoreSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //预定量统计
        getProBrowsingSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetProBrowsingSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },


        //CS馆藏资料年度新增统计
        GetYearNewAddGetSA(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetYearNewAddGetSA().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })

            })

        },
        //CS档案借阅量年度新增
        getYearNewAddBrowsingSA(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetYearNewAddBrowsingSA().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //首页，预定量查询(值，订单数)
        getHomeProBrowsingNumberSA(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetHomeProBrowsingNumberSA().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //首页，预定量查询（饼图，按资料类型划分）
        getHomeProBrowsingCategorySA(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetHomeProBrowsingCategorySA().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //首页，预定量查询（饼图，按形成区划划分）
        getHomeProBrowsingDistirctSA(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetHomeProBrowsingDistirctSA().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //获取区划
        getDivision(data?: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetDivision(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }

                })

            })

        },
        //获取所属行业
        getProfession(): Promise<any> {
            return new Promise((resolve, reject) => {
                Profession().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }
                })
            })
        },
        //CS馆藏资料月度新增统计折线图
        getMonthNewAddGetSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetMonthNewAddGetSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }
                })
            })
        },
        //CS档案借阅量月度新增折线图
        getMonthNewAddBrowsingSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetMonthNewAddBrowsingSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        reject(res)
                    }
                })
            })
        },

        //排行
        //CS档案借阅量排名
        getBrowsingNumberSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowsingNumberSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "档案借阅量排名获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS当前借阅量--按资料类别分布
        getBrowsingNumberCategorySA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowsingNumberCategorySA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "档案资料类别排名获取失败")
                        reject(res)
                    }
                })
            })
        },
        //现状统计
        //CS当前馆藏资料统计--按年份分布
        getGeoDataYearSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetGeoDataYearSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)
                    } else {
                        ElMessage.error(res.msg || "馆藏资料年度统计获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS当年馆藏资料统计
        getGeoDataSA(): Promise<any> {
            return new Promise((resolve, reject) => {
                GetGeoDataSA().then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS当年馆藏资料统计
        GetGeoDataByYearSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetGeoDataByYearSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "馆藏资料年代统计获取失败")
                        reject(res)
                    }
                })
            })
        },

        /* ---------------借阅利用统计 -按日期统计-------------------------*/
        //CS查询量统计（柱状图）--按年月日分类- 年分类
        getSearchRecoreYearSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetSearchRecoreYearSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS查询量统计（柱状图）--按年月日分类- 月分类
        getSearchRecoreMonthSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetSearchRecoreMonthSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS查询量统计（柱状图）--按年月日分类- 日分类
        getSearchRecoreDaySA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetSearchRecoreDaySA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS借阅量统计（柱状图）--按年月日分类- 年分类
        getBrowsingRecoreYearSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowsingRecoreYearSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS借阅量统计（柱状图）--按年月日分类- 月分类
        getBrowsingRecoreMonthSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowsingRecoreMonthSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //CS借阅量统计（柱状图）--按年月日分类- 日分类
        getBrowsingRecoreDaySA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowsingRecoreDaySA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //网站浏览量- 年分类
        getBrowseNumberYearSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowseNumberYearSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //网站浏览量- 月分类
        getBrowseNumberMonthSA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowseNumberMonthSA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },
        //网站浏览量- 日分类
        getBrowseNumberDaySA(data: any): Promise<any> {
            return new Promise((resolve, reject) => {
                GetBrowseNumberDaySA(data).then((res: any) => {
                    if (res.code === 200) {
                        resolve(res)

                    } else {
                        ElMessage.error(res.msg || "获取失败")
                        reject(res)
                    }
                })
            })
        },

        /* ---------------借阅利用统计 -按日期统计 end -------------------------*/
        //定义y轴刻度
        yearOnYearAmplificationEchartsYData(data: object[], valueName: string) {
            let sdata = [
                {
                    "profession": "区域地质调查",
                    "yValue": 5
                },
                {
                    "profession": "矿产勘查",
                    "yValue": 19
                },
                {
                    "profession": "水工环地质勘查",
                    "yValue": 27
                },
                {
                    "profession": "物化遥勘查",
                    "yValue": 51
                },
                {
                    "profession": "油气地质",
                    "yValue": 110
                },
                {
                    "profession": "海洋地质",
                    "yValue": 250
                },
                {
                    "profession": "地质科研",
                    "yValue": 1220
                },
                {
                    "profession": "技术方法",
                    "yValue": 220
                },
                {
                    "profession": "其他",
                    "yValue": 400
                }
            ]
            const MaxNum = this.getMaxNum(sdata, valueName)

            // let yAxis = [0, 10, parseInt((0.1 * MaxNum)), parseInt(0.2 * MaxNum), parseInt(0.5 * MaxNum), parseInt(MaxNum)]
            // return yAxis
        },
        //获取最大值
        getMaxNum(data: object[], valueName: string) {
            return Math.max.apply(Math, data.map((item: any) => { return item[valueName] }))

        }
    },

});